package com.ysy.common.resp;

import lombok.Getter;

import java.util.Arrays;

/**
 * @ClassDescription: 响应状态码枚举类
 * @Author:姚斯羽
 * @Create:2025/3/12 14:01
 **/
@Getter
public enum ReturnCodeEnum
{
    /**操作失败**/
    RC999(999,"操作XXX失败"),
    /**操作成功**/
    RC200(200,"success"),

    /**系统规则不满足**/
    RC203(203,"系统规则不满足要求,请稍后再试!"),
    /**授权规则不通过**/
    RC204(204,"授权规则不通过,请稍后再试!"),
    /**参数不正确**/
    RC205(205,"参数异常!"),
    /**access_denied**/
    RC403(403,"无访问权限,请联系管理员授予权限"),
    /**access_denied**/

    RC404(404,"404页面找不到的异常"),
    /**服务异常**/
    RC500(500,"系统异常，请稍后重试"),
    RC375(375,"数学运算异常，请稍后重试"),



    CLIENT_AUTHENTICATION_FAILED(1001,"客户端认证失败"),
    USERNAME_OR_PASSWORD_ERROR(1002,"用户名或密码错误"),

    BUSINESS_ERROR(3001,"业务逻辑异常"),
    UNSUPPORTED_GRANT_TYPE(3002, "不支持的认证模式"),

    NOT_LOGIN(4001,"未登录"),
    NOT_PERMISSION(4002,"没有权限"),
    USER_DISABLED(4003,"用户被禁用"),
    FILE_NOT_EXIST(4003,"文件下载失败");

    /**自定义状态码**/
    private final Integer code;
    /**自定义描述**/
    private final String message;

    ReturnCodeEnum(Integer code, String message){
        this.code = code;
        this.message = message;
    }

    //遍历枚举V1
    public static ReturnCodeEnum getReturnCodeEnum(Integer code)
    {
        for (ReturnCodeEnum element : ReturnCodeEnum.values()) {
            if(element.getCode().equals(code))
            {
                return element;
            }
        }
        return null;
    }
    //遍历枚举V2
    public static ReturnCodeEnum getReturnCodeEnumV2(Integer code)
    {
        return Arrays.stream(ReturnCodeEnum.values()).filter(x -> x.getCode().equals(code)).findFirst().orElse(null);
    }

}
